import godebug from '../godebug'
export default (function() {

    let levels = godebug.levels;
    window._levels = {};
    for (let i = 0; i < levels.length; i++) {
        window._levels[levels[i]] = console[levels[i]]
            // let level = console[levels[i]];
        window.console[levels[i]] = function() {
            let data = [];
            for (let i = 0; i < arguments.length; i++) {
                data.push(arguments[i]);
            }
            godebug.emit('log', data);
            try {
                //ie8及以下如果设置了安全级别比较高的，console.apply会抛异常
                window._levels[levels[i]].apply(console, arguments);
            } catch (error) {
                var a = Array.prototype.slice.apply(arguments).join(" ");
                window._levels[levels[i]](a)
            }

        }
    }
    try {
        //简写了log输出，这个不会调重写后的console bind为了输出原来打印的地方
        window._log = window._levels['log'].bind(console);
    } catch (error) {
        window._log = function() {
            try {
                //安全级别
                window._levels['log'].apply(console, arguments);
            } catch (error) {
                var a = Array.prototype.slice.apply(arguments).join(" ");
                window._levels['log'](a)
            }
        }
    }
}())